using System.Reflection;
using FluentNHibernate;
using FluentNHibernate.AutoMap;
using NCommon.Util;
using Roommate.Domain.Entities;

namespace Roommate.Infrastructure.Persistence
{
    public class RoommatePersistenceModel : AutoPersistenceModel
    {
        public RoommatePersistenceModel()
        {
            Conventions = new Conventions
                              {
                                  GetForeignKeyNameOfParent = (type => type.Name + "Id"),
                                  GetForeignKeyName = (info => info.Name + "Id"),
                                  GetTableName = (type => Inflector.Pluralize(type.Name)),
                                  GetManyToManyTableName =
                                      ((child, parent) =>
                                       Inflector.Pluralize(child.Name) + "To" + Inflector.Pluralize(parent.Name))
                              };


            AddEntityAssembly(Assembly.GetAssembly(typeof(Room)))
                .Where(entity => entity.Namespace.EndsWith("Entities") &&
                                 entity.GetProperty("Id") != null &&
                                 entity.IsAbstract == false);


        }
    }
}